package view;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;


public class DebugPanel extends JPanel {
	
	private static final long serialVersionUID = 1L;
	
	private static DebugPanel _instance;
	
	private int _fps = 0;
	
	public DebugThread debugThread = new DebugThread();
	
	
	private DebugPanel() {
		this.setBackground(Color.LIGHT_GRAY);
		this.setPreferredSize(new Dimension(80, 100));
	}
	
	public static DebugPanel getInstance() {
		if (null == _instance) {
			_instance = new DebugPanel();
			_instance.debugThread.start();
		}
		return _instance;
	}
	
	public void incFps() {
		_fps += 1;
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		Color c = g.getColor(); 
		g.setColor(Color.LIGHT_GRAY);
		g.fillRect(0, 0, 80, 100);
		g.setColor(Color.BLACK);
		g.drawString("FPS : " + _fps, 10, 10);
		g.setColor(c);
		_fps = 0;
	}
	
	class DebugThread extends Thread {

		public void run() {
			while(true) {
				try {
					repaint();
					sleep( 1000 );
				} catch ( Exception e ) {} 
			}
		}
	}
}
